package com.school.controller.mall;

import com.school.common.Constants;
import com.school.common.IndexConfigTypeEnum;
import com.school.controller.vo.IndexCarouselVO;
import com.school.controller.vo.IndexCategoryVO;
import com.school.controller.vo.IndexConfigGoodsVO;
import com.school.service.CarouselService;
import com.school.service.GoodsCategoryService;
import com.school.service.IndexConfigService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class IndexController {
    @Resource
    private IndexConfigService indexConfigService;
    @Resource
    private CarouselService carouselService;
    @Resource
    private GoodsCategoryService goodsCategoryService;
    @GetMapping({"/","/index","/index.html"})
    public String index(HttpServletRequest  request)
    {
        List<IndexCategoryVO> categories=goodsCategoryService.getCayegoriesForIndex();
        List<IndexCarouselVO> carousels=carouselService.getCarouselsForIndex(Constants.INDEX_CAROUSEL_NUMBER);
        List<IndexConfigGoodsVO> hotGoodses=indexConfigService.getConfigGoodsForIndex(IndexConfigTypeEnum.INDEX_GOODS_HOT.getType(),Constants.INDEX_GOODS_HOT_NUMBER);
        List<IndexConfigGoodsVO> newGoodses=indexConfigService.getConfigGoodsForIndex(IndexConfigTypeEnum.INDEX_GOODS_NEW.getType(),Constants.INDEX_GOODS_NEW_NUMBER);
        List<IndexConfigGoodsVO> recommendGoodses=indexConfigService.getConfigGoodsForIndex(IndexConfigTypeEnum.INDEX_GOODS_RECOMMOND.getType(),Constants.INDEX_GOODS_RECOMMOND_NUMBER);
        request.setAttribute("categories",categories);
        request.setAttribute("carousels",carousels);
        request.setAttribute("hotGoodses",hotGoodses);
        request.setAttribute("newGoodses",newGoodses);
        request.setAttribute("recommendGoodses",recommendGoodses);
        return "mall/index";
    }
    @GetMapping("customer-service")
    public String customerService(HttpServletRequest request)
    {
        request.setAttribute("path","customer-service");
        return "mall/customer-service";
    }

}
